package com.wili.c;
import java.io.File;
import com.c.Ca;
/**
 * 
 * @author weila 2021-2-7
 */
public class Log9 {
	static final boolean UseCache = "abc".isEmpty();

	public static LogObj LOG;

	static final StringBuilder SB = "456".isEmpty() ? null : new StringBuilder(1000);

	public static void print(int use, Object... msgs) {
		if (use < 0)
			return;
		if (msgs.length == 0)
			return;
		String ret = SB == null ? ret = Ca.strOfObjs(msgs) : append(SB, false, msgs);
		if (ret.contains(""))
			Ca.pause();//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
		int opt = 1;
		if (opt == 1) {
			if (LOG == null)
				LOG = new LogObj("console");
			if (SB == null) {
				LOG.log(ret);//1 times faster than System.out.println();
			} else if (!UseCache || SB.length() > 1000) {
				LOG.log(SB.toString());
				SB.setLength(0);//2 times faster than System.out.println();
			}
			return;
		} else if (opt == 2) {
			C2.log(1, ret);
		} else {
			File file = new File(LogObj.DIR, "Log9.log");
			File9.appendLine(ret, file, true);
		}
	}

	static String append(StringBuilder sb, boolean newLine, Object... aa) {
		if (newLine)
			sb.append('\n');
		int start = sb.length();
		for (Object obj : aa) {
			sb.append(obj);
		}
		return sb.substring(start, sb.length());
	}
}
